package com.shundr.shipper.common.view;

import java.util.ArrayList;
import java.util.List;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;

import com.actionbarsherlock.view.Window;
import com.shundr.shipper.R;
import com.shundr.shipper.base.BaseDialog;
import com.shundr.shipper.common.adapter.AttributeAdapter;
import com.shundr.shipper.common.model.AttributeInfo;

public class DialogResendTime extends BaseDialog {
	
	@SuppressWarnings("unused")
	private Context mContext;
	private CListView mListView;
	private AttributeAdapter mAdapter;
	private List<AttributeInfo> mList = new ArrayList<AttributeInfo>();
	
	private AttributeItemClickListener itemClickListener;
	
	public DialogResendTime(Context context,AttributeItemClickListener listener){
		this.mContext = context;
		this.itemClickListener = listener;
	}
	
	@SuppressLint("InflateParams")
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		getDialog().requestWindowFeature((int) Window.FEATURE_NO_TITLE);
		setStyle(STYLE_NO_TITLE, R.style.dialog_no_overlay);
		View view = inflater.inflate(R.layout.dialog_order_status, null);
		mListView = (CListView) view.findViewById(R.id.lv_list);
		init();
		mAdapter = new AttributeAdapter(mList, getActivity());
		mListView.setAdapter(mAdapter);
		
		mListView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				try {
					if(itemClickListener == null)
						return;
					itemClickListener.onItemClick(mList.get(position - 1));
				} catch (Exception e) {
					e.printStackTrace();
				}
				dismiss();
			}
		});
		return view;
	}
	
	private void init(){
		try {
			mList.add(new AttributeInfo("0", "不重发"));
			mList.add(new AttributeInfo("2", "重发2次"));
			mList.add(new AttributeInfo("4", "重发4次"));
			mList.add(new AttributeInfo("6", "重发6次"));
			mList.add(new AttributeInfo("8", "重发8次"));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		return super.onCreateDialog(savedInstanceState);
	}
	
	public interface AttributeItemClickListener{
		public void onItemClick(AttributeInfo info);
	}

	
}
